import { BaseResponse } from "@/util";
import { CreateGoodsReq, DeleteGoodsReq, FormatHTMLReq, FormatHTMLResp, GetGoodsReq, UpdateGoodsReq } from "@/typings/goods";
import { PageData, request } from "@/util";
import { GoodsRecord } from "@/views/goods/GoodsList/GoodsListType";
import { AxiosResponse } from "axios";

export const getGoods = async (params: GetGoodsReq = {}) => {
	const { data } = await request.get<GetGoodsReq, AxiosResponse<BaseResponse<PageData<GoodsRecord[]>>>>("/admin/goods", { params });
	return data;
};
export const createGoods = async (body: CreateGoodsReq) => {
	const { data } = await request.post<CreateGoodsReq, AxiosResponse<BaseResponse>>("/admin/goods", body);
	return data;
};
export const updateGoods = async (body: UpdateGoodsReq) => {
	const { data } = await request.patch<UpdateGoodsReq, AxiosResponse<BaseResponse>>("/admin/goods", body);
	return data;
};
export const deleteGoods = async (body: DeleteGoodsReq) => {
	const { data } = await request.delete<DeleteGoodsReq, AxiosResponse<BaseResponse>>("/admin/goods", { data: body });
	return data;
};
export const formatHTML = async (body: FormatHTMLReq) => {
	const { data } = await request.post<FormatHTMLReq, AxiosResponse<BaseResponse<FormatHTMLResp>>>("/admin/goods/formatHTML", body);
	return data;
};
